
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
    pageEncoding="ISO-8859-1"%>
<%@ page import="java.sql.*, java.util.*, support.*" %>

<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<%@ taglib uri="http://struts.apache.org/tags-html" prefix="html" %>
<%@ taglib uri="http://struts.apache.org/tags-logic" prefix="logic" %>

<<<<<<< .mine
<%

String url = "jdbc:postgresql://localhost/Applications";
Connection conn = null;
Statement stmt = null;
PreparedStatement ps = null;
ResultSet rs = null;
String instruc = null;

support s = new support();

//get path to load list infos
String path1 = config.getServletContext().getRealPath("countries.txt");
Vector countries = s.getCountries(path1);  

String path2 = config.getServletContext().getRealPath("universities.txt");
Vector universities = s.getUniversities(path2);

String path3 = config.getServletContext().getRealPath("majors.txt");
Vector majors = s.getMajors(path3);  

String path4 = config.getServletContext().getRealPath("specializations.txt");
Vector specializations = s.getSpecializations(path4);


try {
        // Registering Postgresql JDBC driver
        Class.forName("org.postgresql.Driver");
        // Open a connection to the database        
        conn = DriverManager.getConnection(
                "jdbc:postgresql://localhost:5432/Applications", "postgres",
                "postgres");
        // Create the statement
        stmt = conn.createStatement();

        rs = stmt.executeQuery("SELECT * FROM access");
        int loadDB = 0;
        
        //get access to check if we need to load information again
        while( rs.next() )
        {
                loadDB = rs.getInt("accessed");
        }
        
//we need to load it        
if( loadDB == 0 )
{        
        //change access to 1 so we don't have load again next time
        ps = conn.prepareStatement("INSERT INTO access(accessed)" +
                                           " VALUES(?)");
        ps.setInt(1,1);
        ps.executeUpdate();
        
        // store list of countries into database
        for( int i = 0; i < countries.size(); i++ )
        {
                instruc = "INSERT INTO Countries(ID,Country)" +
                          "VALUES(?,?)";
                ps = conn.prepareStatement(instruc);        
                ps.setInt(1,i+1);
                ps.setString(2, countries.get(i).toString() );
                ps.executeUpdate();                
        }
        
int count = 0;
        
        // store list of universities into database
        for( int i = 0; i < universities.size(); i++ )
        {
                Vector tuple = (Vector)universities.get(i);
            	String state = (String)tuple.get(0);
                instruc = "INSERT INTO Universities(ID,Location,University)" +
                          "VALUES(?,?,?)";
                ps = conn.prepareStatement(instruc);        
                for( int j = 0; j < ((Vector)(tuple.get(1))).size(); j++ )
                {
                  String name = (String)((Vector)(tuple.get(1))).get(j);
                  ps.setInt(1,count);
                  ps.setString(2, state);
                  ps.setString(3, name );
                  ps.executeUpdate();
                  count++;
                }
                count++;
        } 
 
        // store list of majors into database
        for( int i = 0; i < majors.size(); i++ )
        {
                instruc = "INSERT INTO Disciplines(ID,Discipline) VALUES(?,?)";
                ps = conn.prepareStatement(instruc);
                ps.setInt(1,i+1);
                ps.setString(2, majors.get(i).toString() );
                ps.executeUpdate();                
        }
        
        // store list of specializations into database
        for( int i = 0; i < specializations.size(); i++ )
        {
                instruc = "INSERT INTO Specializations(ID,Specialization) VALUES(?,?)";
                ps = conn.prepareStatement(instruc);
                ps.setInt(1,i+1);
                ps.setString(2, specializations.get(i).toString() );
                ps.executeUpdate();                
        }
    ps.close();
}  
    rs.close();
    stmt.close();
    conn.close();
} catch (SQLException e) 
{ 
  System.out.println(e);
}     

	request.getSession().setAttribute("uname",request.getRemoteUser());
	if(request.isUserInRole("admin")) 
	{
%>
		<logic:redirect forward="ChairsHome"/>
<%	
	}
	else if(request.isUserInRole("student"))
	{
%>
		<logic:redirect forward="myApplication"/>
<%		
	}
	else
	{
%>
    	<logic:redirect forward="Reviewer"/>
<%
	}
%>
